package com.netty.server;

import com.common.protobuf.MessageModule;
import com.execute.MessageTask4Request;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 顾志杰
 * @date 2021/3/12-10:30
 */
public class ServerHandler extends ChannelInboundHandlerAdapter {

    ThreadPoolExecutor workerPool = new ThreadPoolExecutor(
            5,
            10,
            60L,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(4000),
            new ThreadPoolExecutor.DiscardOldestPolicy());

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        MessageModule.Message request = (MessageModule.Message) msg;
        workerPool.submit(new MessageTask4Request(request,ctx));
    }
}
